package net.xxcxcxcx.xc_enhancedmob.render.boss_bar.column.sever;

import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
import net.xxcxcxcx.xc_enhancedmob.render.boss_bar.column.BaseCustomBossBarColumn;
import net.xxcxcxcx.xc_enhancedmob.render.boss_bar.unit.sever.SeverCustomBossBar;

import java.util.UUID;

public class SeverCustomBossBarColumn extends BaseCustomBossBarColumn {
    public SeverCustomBossBarColumn(UUID uuid, Text name) {
        this(uuid, name, false);
    }

    public SeverCustomBossBarColumn(UUID uuid, Text name, Boolean showname) {
        this(uuid, name, showname, 0);
    }

    public SeverCustomBossBarColumn(UUID uuid, Text name, Boolean showname, int sortcount) {
        setUuid(uuid);
        setName(name);
        setShowname(showname);
        setSortCount(sortcount);
        getUuid().setDirty(false);
        getName().setDirty(false);
        getShowname().setDirty(false);
        getSortCount().setDirty(false);
    }

    public SeverCustomBossBarColumn(NbtCompound nbtCompound) {
        readCustomDataFromNbt(nbtCompound);
    }

    @Override
    public void readCustomDataFromNbt(NbtCompound nbt) {
        for (String s : nbt.getKeys()) {
            if (s.equals("name")) {
                setName(Text.Serializer.fromJson(nbt.getString("name")));
                continue;
            }
            if (s.equals("showname")) {
                setShowname(nbt.getBoolean("showname"));
                continue;
            }
            if (s.equals("uuid")) {
                setUuid(nbt.getUuid("uuid"));
                continue;
            }
            if (s.equals("SortCount")) {
                setSortCount(nbt.getInt("SortCount"));
                continue;
            }
            getBossBars().add(new SeverCustomBossBar(nbt.getCompound(s)));
        }
    }
}
